//页面初始化
$(function(){
	
	//索引状态
	initIndices();
	
	$(document).on("click","#delindex",function(){
		
		if(confirm('确定删除索引？')){
			$.ajax({
				
				 url: "/log/delIndices.action",
				 data:{"indexName":$(this).parent().siblings(".exindex").text()},
				 type:"GET",
				 success: function(result){
					 result = eval("result="+result);
					 if(result.acknowledged==true){
						 alert("删除成功");
						 window.location.reload();
					 }
				      
				 }
				
			});
		}
	});
});

function initIndices() {
	$.ajax({
		
		 url: "/log/catIndices.action", 
		 type:"GET",
		 success: function(result){
		      var str = "<tr class='tb_head'><th>集群健康状态</th><th>状态</th><th>索引名称</th><th>文档数量</th><th>删除文档数量</th><th>总占容量</th><th>pri占容量</th><th>操作</th></tr>";
		      for(var a in result){
		    	  var health="<div style='background-color:"+result[a].health+";height:10px;width:10px;margin:0 auto'><div>";
		    	  
		    	  str+="<tr class='tb_body'><td>"+health+"</td><td>"+result[a].status+"</td><td class='exindex'>"+result[a].index+"</td><td>"+result[a].docsCount+"</td><td>"+result[a].docsDeleted+"</td><td>"+result[a].storeSize+"</td><td>"+result[a].priStoreSize+"</td><td><button type='button' id='delindex'>删除索引</button></td></tr>";
		      }
		      $("#data_result").append(str);
		 }
		
	});
}

